package cqrtplm.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.entity.RtCertEuemissionsnoDO;
import cqrtplm.service.RtCertEuemissionsnoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "认证-欧排号")
@RequestMapping("/rest"+RouteConstant.RATO + "cert/euemissionsno/" + "v1")
public class RtCertEuemissionsnoController {

    @Resource
    private RtCertEuemissionsnoService rtCertEuemissionsnoService;

    @PostMapping("/list")
    @ApiOperation("获取欧排号列表")
    public ResponseResult list(@RequestBody RtCertEuemissionsnoDO rtCertEuemissionsno) {
        List<RtCertEuemissionsnoDO> list = rtCertEuemissionsnoService.selectRtCertEuemissionsnoList(rtCertEuemissionsno);
        return ResponseResult.success(list);
    }

    @PostMapping("/pagelist")
    @ApiOperation("分页获取欧排号列表")
    public ResponseResult<PageInfo<RtCertEuemissionsnoDO>> pagelist(
            @RequestBody RtCertEuemissionsnoDO rtCertEuemissionsno,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<RtCertEuemissionsnoDO> list = rtCertEuemissionsnoService.selectRtCertEuemissionsnoList(rtCertEuemissionsno);
        return ResponseResult.success(new PageInfo<>(list));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取欧排号详情")
    public ResponseResult getById(@PathVariable String id) {
        return ResponseResult.success(rtCertEuemissionsnoService.selectRtCertEuemissionsnoById(id));
    }

    @GetMapping("/no/{euEmissionsNo}")
    @ApiOperation("根据欧排号获取详情")
    public ResponseResult getByNo(@PathVariable String euEmissionsNo) {
        return ResponseResult.success(rtCertEuemissionsnoService.selectRtCertEuemissionsnoByNo(euEmissionsNo));
    }

    @PostMapping("/add")
    @ApiOperation("新增欧排号")
    public ResponseResult add(@RequestBody RtCertEuemissionsnoDO rtCertEuemissionsno) {
        return ResponseResult.success(rtCertEuemissionsnoService.insertRtCertEuemissionsno(rtCertEuemissionsno));
    }

    @PostMapping("/edit")
    @ApiOperation("修改欧排号")
    public ResponseResult edit(@RequestBody RtCertEuemissionsnoDO rtCertEuemissionsno) {
        return ResponseResult.success(rtCertEuemissionsnoService.updateRtCertEuemissionsno(rtCertEuemissionsno));
    }

    @DeleteMapping("/del")
    @ApiOperation("删除欧排号")
    public ResponseResult remove(@RequestBody List<String> ids) {
        return ResponseResult.success(rtCertEuemissionsnoService.deleteRtCertEuemissionsnoByIds(ids));
    }
}